//
//  Client_RF225_feiyiku.swift
//  Wmsmobile
//
//  Created by xuNick on 16/10/9.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}

fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l > r
  default:
    return rhs < lhs
  }
}


class Client_RF225_feiyikuController:HDFounctionBaseController , HDBarcodeInputCellInputDelegate {
    //MARK: - property
    var dataArray = [["移出货位"],["移入货位"]]
    override var firstActiveIndexPath: IndexPath?{
        set{
        }
        get{
            return IndexPath(item: 0, section: 0)  //在这里添加需要进入界面就激活的cell的位置
        }
    }
    //MARK: - delegate
    
    func clicKReturn(_ cell: HDBarcodeInputCell) {
        let indexPath = self.tableView.indexPath(for: cell)
        if (indexPath as NSIndexPath?)?.section == 0{
            self.getData(["piFromBin" : self.getText(0, inSection: 0) ?? ""], bodyMethod: "chkBin", suffix: "330", success: { (dict) in
                self.goNextCell(cell, nextInsexPath: IndexPath(item: 0, section: 1))
            }) { (dict) in
                cell.state = .wrong
            }
        }else{ //代表第二个cell
            self.getData(["piFromBin" : self.getText(0, inSection: 0) ?? "" , "piToBin" : self.getText(0, inSection: 1) ?? "" , "piOperator" : (userInfo?.userName)!], bodyMethod: "updMoveInv", suffix: "330", success: { (dict) in
                self.showMessage("移库成功", success: true)
                self.setText(0, inSection: 0, text: nil)
                self.setText(0, inSection: 1, text: nil)
                self.goNextCell(cell, nextInsexPath: IndexPath(item: 0, section: 0))
                }, failed: { (dict) in
                    cell.state = .wrong
            })
        }
    }
    //MARK: - private
    override func isEmpty() -> (Bool) { //判断控制器是否为空，必须要实现
        if let cell = cellsDict[String(describing: IndexPath(item: 0, section: 0))] as? HDBarcodeInputCell{
            if cell.codeInputView.textField.text?.characters.count > 0 {
                return false
            }else{
                return true
            }
        }
        return false
    }
    //MARK: - tableviewDatasource
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let cell = cellsDict[String(describing: indexPath)] {
            return cell
        }else{
            let cell = HDBarcodeInputCell()
            cell.titleView.text = dataArray[(indexPath as NSIndexPath).section].first
            cell.InputDelegate = self
            cellsDict.updateValue(cell, forKey: String(describing: indexPath))
            return cell
        }
    }
    
    //MARK: - tableViewDelegate
}
